package com.util.cdb.service.impl;

import com.util.cdb.bean.AbstractHandler;
import com.util.cdb.bean.DataFactory;
import com.util.cdb.bean.vo.QueryOperationPageVO;
import com.util.cdb.bean.vo.QueryOperationVO;
import com.util.cdb.service.OperationService;
import com.util.cdb.util.HikariConfigUtil;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * @description: 转化成SQL实现类
 * @author: fengfazheng
 * @create: 2021-12-26 22:57
 **/
@Service
public class OperationServiceImpl implements OperationService {

    @Override
    public List<String> queryListByOperation(QueryOperationVO queryOperationVO) throws SQLException {
        AbstractHandler handler = DataFactory.getInvokeStrategy(queryOperationVO.getDbType());
        String sql = handler.getSql(queryOperationVO.getOperation());
        return HikariConfigUtil.getJdbcTemplate(queryOperationVO).queryForList(sql, String.class);
    }

    @Override
    public List<Map<String, Object>> queryListMapByOperation(QueryOperationPageVO queryOperationPageVO) throws SQLException {
        AbstractHandler handler = DataFactory.getInvokeStrategy(queryOperationPageVO.getDbType());
        String sql = handler.getPageSql(queryOperationPageVO);
        return HikariConfigUtil.getJdbcTemplate(queryOperationPageVO).queryForList(sql);
    }
}
